package com.wondersgroup.fjzlpt.tbxt.controller.rest.zh;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.quick.framework.util.QuickPrincipalUtils;
import com.wondersgroup.fjzlpt.tbxt.beans.req.zhNb.QueryNbInfoReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.req.zhNb.SaveReqBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.BaseRespBean;
import com.wondersgroup.fjzlpt.tbxt.beans.resp.zhNb.QueryNbInfoRespBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSONObject;
import com.quick.framework.boot.web.utils.RequestUtils;
import com.quick.framework.boot.web.wapper.QuickPrincipal;
import com.wondersgroup.fjzlpt.tbxt.service.inter.zh.ZhNbService;
import org.springframework.web.bind.annotation.RestController;

/**
 * 综合年报
 */
@RestController
@RequestMapping("/zhnb")
@Api(value = "综合年报标准接口", tags = "ZhNbRestController", description = "综合年报API")
public class ZhNbRestController {

    @Autowired
    private ZhNbService zhService;

    /**
     * 保存或修改
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "保存或修改", notes = "保存或修改综合年报", response = BaseRespBean.class)
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public JSONObject save(HttpServletRequest request, SaveReqBean saveReqBean) {
        Map<String, String> map = RequestUtils.GetParameterMap(request);

        return zhService.save(map);
    }

    /**
     * 查询
     *
     * @param request
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询综合年报", response = QueryNbInfoRespBean.class)
    @RequestMapping(value = "/queryNbInfo", method = RequestMethod.POST)
    public JSONObject queryNbInfo(HttpServletRequest request, QueryNbInfoReqBean queryNbInfoReqBean) {
        Map<String, String> map = RequestUtils.GetParameterMap(request);
        if (StringUtils.isEmpty(map.get("YLJGID"))) {
            map.put("YLJGID", QuickPrincipalUtils.getPtjgID(request));
            QuickPrincipal principal = (QuickPrincipal) request.getUserPrincipal();
            JSONObject userInfo = principal.getUserInfo();
            map.putAll(JSONObject.toJavaObject(userInfo, Map.class));
        }

        return zhService.queryByNfAndYljgid(map);
    }
}
